<?ob_start();
header("Content-Type:   text/html;   charset=utf-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pramga: no-cache"); 
session_start();
ini_set('magic_quotes_gpc', 'Off');
// ini_set("display_errors", 0);
// error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(E_ALL ^ E_DEPRECATED);
//
include_once('../include/conn_db.php');
mysql_connect(HOST,NAME,PASS) or die(mysql_error());
mysql_select_db(DBNAME);
mysql_query('SET NAMES '.CODEPAGE);

include_once("inc_config.php");//后台的配置
include('../include/db_class.php');
include_once("inc_function.php");// 里面有生成缩略图的函数,翻页函数

$mydb=new mydb();//初始化


///////////////////////////////////////////////检测cookie判断是自动登录/////////////////////////////////////////////
if(!isset($_SESSION['adminName'])){
	if(isset($_COOKIE['cookie_admin'])){
		$_SESSION['adminName']=$_COOKIE['cookie_admin'];
		#得到ID和权限
		$rr1=mysql_fetch_assoc(mysql_query("select * from ".TABLE_C."admin where name='".$_SESSION['adminName']."'"));
		$_SESSION['adminId']=$rr1['id'];
		$_SESSION['adminPower']=$rr1['power'];
	}
}

////////////////////////////////////////////////检测是否登录 //////////////////////////////////////////////////
if(!isset($_SESSION['adminName'])){
	@mysql_close();
	echo "<script>alert('你必需先登录');window.parent.location='login.php'</script>";
	exit;
}

////////////////////////////////////////////// 生成一个随机字符串 //////////////////////////////////////////////
function randFilename(){
	$str="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return substr(str_shuffle($str),5,20);
}


//////////////////////////////////////////////如果读取数据库记录0，显示空行//////////////////////////////////////////////
function showemptyrs($rs){
	 if(mysql_num_rows($rs)==0){
	 	echo "<tr><td colspan=20 style='text-align:center;font-weight:bold;'>没有数据</td></tr>";
	 }
}


/////////////////////////////////////////////////得到当前文件名//////////////////////////////////////////////////
$purl=parse_url(request_uri());#分析URL
$lastpath=substr($purl['path'],strrpos($purl['path'],'/')+1);#得到路径和文件名，把文件名取出来
@$lastquery=$purl['query'];#得到参数


/////////////////////////////////////////////生成上一个页面的连接//////////////////////////////////////////////////
//$cururl=$_SESSION['lastUrl']; #每次在正常有inc_foot.php的页面，会调用下面的函数，生成最后访问的url，而每次页面中头部会赋值为最后访问的url
$cururl= url_referer() ; #试用来路url
function buildLast(){
	global $lastpath;//声名外部变量
	global $lastquery;//声名外部变量
	$_SESSION['lastUrl']=$lastpath.'?'.$lastquery;#文件名跟参数连接
}


/////////////////////////////////////////////  显示来路url  /////////////////////////////////////////////
function url_referer(){
	$url       = $_SERVER["HTTP_REFERER"];   //获取完整的来路URL
	$str   = str_replace("http://","",$url);  //去掉http://
	$strdomain = explode("/",$str);               // 以“/”分开成数组
	return $strdomain[2];
}


////////////////////////////////////////////////显示当前管理管理位置///////////////////////////////////////////
function local($showtext){
	global $lastpath;//声名外部变量,才可调用
	global $lastquery;//声名外部变量,才可调用
	echo "<div class=local id=local1>";
	echo "<a href='index.php' target='_top'>
	<i class=\"fa fa-lg fa-home\"></i></a>当前位置：<b>$showtext</b> &nbsp;
	<input type='text' size=50 value='$lastpath?$lastquery' onclick='this.select();' class='form-control input-sm'>";
	//echo "当前位置：<b> $showtext </b>";
	echo '<a href="#" onclick="location.reload()"  class="btn btn-xs btn-success">刷新</a>';
	echo '<a href=""   class="btn btn-xs btn-success" target="_blank">新页面打开</a>';
	echo "</div>";
}

#////////////////////////////////////////////////显示删除按钮 函数////////////////////////////////////////////////
function del($id,$file,$comfirm=1){
	if($comfirm==0){
		echo "<a class=\"btn btn-danger btn-xs\" href=\"?act=del&id=$id&file=$file\">删除</a>";
	}else{
		echo "<a class=\"btn btn-danger btn-xs\" onclick=\"if(confirm('确定删除吗')){window.location='?act=del&id=$id&file=$file'}\">删除</a>";
	}
}

//////////////////////////////////////////////////处理完跳转的////////////////////////////////////////////////////
function gourl($text,$addr){
	global $js_backtime;
	echo "<div style='text-align:center;font:12px;margin-top:200px'>";
	echo "<div  style='color:blue;font-size:20px;'>".$text."</div><br>返回地址：<a href='$addr' style='color:blue' >$addr</a>";
	echo "</div>";
	//echo "<div id='DIValert'></div>";
	echo  "<script>goURL('".$addr."','".$js_backtime."')</script>";
}

///////////////////////////////////////////////权限判断///////////////////////////////////////////////
function pmanage($ptext){
	if(strpos($_SESSION['adminPower'],"|$ptext|")!==false){
		return true;
	}
}

///////////////////////////////用于提交的时候判断是否有内容 /////////////////////////////////////
function isPostNull($value1,$infot){
	if(strlen($value1)==0){
		echo "<script>alert('$infot');window.history.back();</script>";
		exit;
	}
}


///////////////////////////////显示出排序按钮,是act判断动作的，是后来某些页页添加的功能/////////////////////////////////
function series_order_button2($orderNum,$id){
	echo "<input type='text' size='1' value='$orderNum' readonly class='form-control'>";
	echo "<a class='btn btn-xs btn-default' href=?act=order&id=$id&ordernum=".($orderNum+1)." >↑</a>";
	echo "<a class='btn btn-xs btn-default' href=?act=order&id=$id&ordernum=".($orderNum==0?0:$orderNum-1).">↓</a>";
}

///////////////////////////////计算页面时间///////////////////////////////////////
class runtime{
	var $StartTime = 0;
	var $StopTime = 0;
	function get_microtime() {
	list($usec, $sec) = explode(' ', microtime());
	return ((float)$usec + (float)$sec);
	}
	function start() { $this->StartTime = $this->get_microtime(); }
	function stop() { $this->StopTime = $this->get_microtime(); }
	function spent() { return "页面执行时间：".round(($this->StopTime - $this->StartTime) * 1000, 1)."毫秒";  }
}

////////////////////////////////调用编辑器的过程 /////////////////////////////////////////
function myEditor($editorobj='fckeditor',$formname='message',$contents='',$width=300,$height=200){
	switch($editorobj){
		case 'fckeditor':
			include_once('fckeditor/fckeditor.php');
			$FCKeditor = new FCKeditor($formname) ; // 创建FCKeditor实例
			$FCKeditor->BasePath = 'fckeditor/'; // 设置FCKeditor目录地址
			$FCKeditor->Width=$width; //设置显示宽度
			$FCKeditor->Height=$height; //设置显示高度的高度
			$FCKeditor->Value= $contents ;
			$FCKeditor->Create() ; // 创建编辑器
			break;
		case 'xheditor':
			echo '<script type="text/javascript" src="xheditor-1.2.1/xheditor-1.2.1.min.js"></script>';
			echo '<script type="text/javascript" src="xheditor-1.2.1/xheditor_lang/zh-cn.js"></script>';
			echo "<textarea  class=\"xheditor {tools:'mfull',width:'$width',height:'$height',disableContextmenu:true,";
			echo "cleanPaste:2,upBtnText:'upload',upImgUrl:'xheditor-1.2.1/upload.php'}\" name='$formname'  id='$formname'>$contents</textarea>";

			//下面这个方式也解决不了在本地拖动多张图片上传的错误
			//echo "<textarea name='$formname'  id='$formname' style='width:".$width."px;height:".$height."px'>$contents</textarea>";
			//echo "<script>$('#$formname').xheditor({upLinkUrl:\"xheditor-1.2.1/upload.php\",upLinkExt:\"zip,rar,txt\",upImgUrl:\"xheditor-1.2.1/upload.php\",upImgExt:\"jpg,jpeg,gif,png\",upFlashUrl:\"xheditor-1.2.1/upload.php\",upFlashExt:\"swf\",upMediaUrl:\"xheditor-1.2.1/upload.php\",upMediaExt:\"wmv,avi,wma,mp3,mid\"});</script>";

			break;
		case 'tqeditor';
			echo '<script type="text/javascript" src="tqeditor-2.3.6/TQEditor.js" ></script>';
			echo "<textarea name=\"$formname\"  id=\"$formname\" style='width:".$width."px;height:".$height."px'>$contents</textarea><script type='text/javascript'>new TQEditor('$formname',{advToolbarMode:true});</script>";
			break;
		case 'kindeditor';
			echo '<link rel="stylesheet" href="kindeditor-4.1.10/themes/default/default.css" />';
			echo '<script charset="utf-8" src="kindeditor-4.1.10/kindeditor-min.js"></script>';
			echo '<script charset="utf-8" src="kindeditor-4.1.10/lang/zh_CN.js"></script>';
			echo "<textarea name=\"$formname\" style=\"width:".$width."px;height:".$height."px;visibility:hidden;\">$contents</textarea>";
			echo "<script>
			var editor;
			KindEditor.ready(function(K) {				editor = K.create('textarea[name=\"$formname\"]', {allowFileManager : true});			});
			</script>";
			break;
		case 'ueditor';
			echo '<script type="text/javascript" charset="gbk" src="ueditor1_3_6-gbk-php/ueditor.config.js"></script>';
			echo '<script type="text/javascript" charset="gbk" src="ueditor1_3_6-gbk-php/ueditor.all.min.js"> </script>';
			echo '<script type="text/javascript" charset="gbk" src="ueditor1_3_6-gbk-php/lang/zh-cn/zh-cn.js"></script>';
			echo "<textarea name='$formname' id='$formname' style='width:".$width."px;height:".$height."px'>$contents</textarea>";
			echo "<script>UE.getEditor('$formname');</script>";
			break;
		case 'ueditor136utf8';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_3_6-utf8-php/ueditor.config.js"></script>';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_3_6-utf8-php/ueditor.all.min.js"> </script>';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_3_6-utf8-php/lang/zh-cn/zh-cn.js"></script>';
			echo "<textarea name='$formname' id='$formname' style='width:".$width."px;height:".$height."px'>$contents</textarea>";
			echo "<script>UE.getEditor('$formname');</script>";
			break;
		case 'ueditor143utf8';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_4_3_1-utf8-php/ueditor.config.js"></script>';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_4_3_1-utf8-php/ueditor.all.min.js"> </script>';
			echo '<script type="text/javascript" charset="utf-8" src="ueditor1_4_3_1-utf8-php/lang/zh-cn/zh-cn.js"></script>';
			echo "<textarea name='$formname' id='$formname' style='width:".$width."px;height:".$height."px'>$contents</textarea>";
			echo "<script>UE.getEditor('$formname');</script>";
			break;

		case 'ueditorqiniu';
			echo '<script type="text/javascript" charset="utf-8" src="utf8_qiniu_ueditor/ueditor.config.js"></script>';
			echo '<script type="text/javascript" charset="utf-8" src="utf8_qiniu_ueditor/ueditor.all.min.js"> </script>';
			echo '<script type="text/javascript" charset="utf-8" src="utf8_qiniu_ueditor/lang/zh-cn/zh-cn.js"></script>';
			echo "<textarea name='$formname' id='$formname' style='width:".$width."px;height:".$height."px'>$contents</textarea>";
			echo "<script>UE.getEditor('$formname');</script>";
			break;
	}
}


//开始计算页面运行时间
$runtime = new runtime();
$runtime->start();

?>
<!DOCTYPE html>